"""
处理简单 unix_timestamp 取时间的正则表达式类
"""
import re
import logging


def replace_unix_timestamp_now(m):
    """
    unix_timestamp(now()) 或者 unix_timestamp() 转化为 floor(extract(epoch from now()))
    :param m: 。
    :return: 。
    """
    new_date_format = "FLOOR(EXTRACT(EPOCH FROM NOW()))"
    return new_date_format


def replace_simple_unix_timestamp(all_the_text):
    logging.info("---- replace_simple_unix_timestamp ----")

    unix_timestamp_patten = re.compile(r"(UNIX_TIMESTAMP|unix_timestamp)\(now\(\)\)")
    result = unix_timestamp_patten.sub(replace_unix_timestamp_now, all_the_text)
    all_the_text = result

    unix_timestamp_patten = re.compile(r"(UNIX_TIMESTAMP|unix_timestamp)\(\)")
    result = unix_timestamp_patten.sub(replace_unix_timestamp_now, all_the_text)
    all_the_text = result

    return all_the_text
